<?php
/*
usage:
php xp_console_package_plugin.php xpframework env_plugin
*/
// 获取传入的参数
$pluginname = $argv[1]; // 默认为 'xpframework'
$env = $argv[2];

// include "xp_function.php";
include "xp_project_function.php";
$src_plugin = "addons/{$pluginname}";
$dist_plugin = "dist/{$pluginname}";
$deploy_plugin = "addons/{$pluginname}/_deploy/{$env}";


deleteDirectory($dist_plugin);
xcopy($src_plugin,$dist_plugin);

$modules = ["admin","api","index",$pluginname];
foreach($modules as $module){
    xcopy("application/{$module}/controller/{$pluginname}","{$dist_plugin}/application/{$module}/controller/{$pluginname}");
    xcopy("application/{$module}/lang/zh-cn/{$pluginname}","{$dist_plugin}/application/{$module}/lang/zh-cn/{$pluginname}");
    xcopy("application/{$module}/model/{$pluginname}","{$dist_plugin}/application/{$module}/model/{$pluginname}");
    xcopy("application/{$module}/validate/{$pluginname}","{$dist_plugin}/application/{$module}/validate/{$pluginname}");
    xcopy("application/{$module}/view/{$pluginname}","{$dist_plugin}/application/{$module}/view/{$pluginname}");
}
xcopy("public/assets/addons/{$pluginname}","{$dist_plugin}/assets");
xcopy("public/assets/js/backend/{$pluginname}","{$dist_plugin}/public/assets/js/backend/{$pluginname}");
xcopy("public/assets/js/frontend/{$pluginname}","{$dist_plugin}/public/assets/js/frontend/{$pluginname}");


// deploy env's config
xcopy($deploy_plugin,$dist_plugin);

// delete 
deleteDirectory("{$dist_plugin}/_deploy");

// package
$ini = parse_ini_file("{$src_plugin}/info.ini");
$version = $ini["version"];
zipDirectory($dist_plugin,"dist/{$pluginname}-{$version}.zip");